package com.insta.java.model;

import java.io.Serializable;
import java.util.Set;

public class User implements  IUser, Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -6608322390116036728L;

	private Integer id;
	private String name;
	private String forname;
	private String login;
	private String password;
	private boolean isAdmin;
	private Set<ILocation> locations;
	
	
	public User(){}
	
	public User(String name, String forname, String login, String password) {
		super();
		this.name = name;
		this.forname = forname;
		this.login = login;
		this.password = password;
	}
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	/* (non-Javadoc)
	 * @see com.insta.java.model.IUser#getName()
	 */
	public String getName() {
		return name;
	}

	/* (non-Javadoc)
	 * @see com.insta.java.model.IUser#setName(java.lang.String)
	 */
	public void setName(String name) {
		this.name = name;
	}

	/* (non-Javadoc)
	 * @see com.insta.java.model.IUser#getForname()
	 */
	public String getForname() {
		return forname;
	}

	/* (non-Javadoc)
	 * @see com.insta.java.model.IUser#setForname(java.lang.String)
	 */
	public void setForname(String forname) {
		this.forname = forname;
	}
	
	/* (non-Javadoc)
	 * @see com.insta.java.model.IUser#getLogin()
	 */
	public String getLogin() {
		return login;
	}

	/* (non-Javadoc)
	 * @see com.insta.java.model.IUser#setLogin(java.lang.String)
	 */
	public void setLogin(String login) {
		this.login = login;
	}

	/* (non-Javadoc)
	 * @see com.insta.java.model.IUser#getPassword()
	 */
	public String getPassword() {
		return password;
	}

	/* (non-Javadoc)
	 * @see com.insta.java.model.IUser#setPassword(java.lang.String)
	 */
	public void setPassword(String password) {
		this.password = password;
	}

	public boolean getIsAdmin() {
		return isAdmin;
	}

	public void setIsAdmin(boolean isAdmin) {
		this.isAdmin = isAdmin;
	}

	@Override
	public String toString() {
		return "User [name=" + name + ", forname=" + forname + ", login="
				+ login + ", isAdmin=" + isAdmin + "]";
	}
	
	public Set<ILocation> getLocations() {
		return locations;
	}

	public void setLocations(Set<ILocation> locations) {
		this.locations = locations;
	}

	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((forname == null) ? 0 : forname.hashCode());
		result = prime * result + (isAdmin ? 1231 : 1237);
		result = prime * result + ((login == null) ? 0 : login.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result
				+ ((password == null) ? 0 : password.hashCode());
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (forname == null) {
			if (other.forname != null)
				return false;
		} else if (!forname.equals(other.forname))
			return false;
		if (isAdmin != other.isAdmin)
			return false;
		if (login == null) {
			if (other.login != null)
				return false;
		} else if (!login.equals(other.login))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (password == null) {
			if (other.password != null)
				return false;
		} else if (!password.equals(other.password))
			return false;
		return true;
	}
}
